#include "StdAfx.h"
#include "correctiondialog.h"

CorrectionDialog::CorrectionDialog( const QVector<int> & playersScoreVector, QWidget * parent )
:   m_playersScoreVector( playersScoreVector ),
    QDialog( parent )
    
{
    ui.setupUi( this );
    QIntValidator * validator = new QIntValidator( -100, 100, this );
    ui.firstLineEdit->setValidator( validator );
    ui.secondLineEdit->setValidator( validator );
    ui.thirdLineEdit->setValidator( validator );
    connect( ui.cancelPushButton, SIGNAL( clicked() ), this, SLOT( reject() ) );
    connect( ui.okPushButton, SIGNAL( clicked() ), this, SLOT( onOk() ) );
    switch (playersScoreVector.count())
    {
    case 1:
        ui.secondLabel->setVisible( false );
        ui.secondLineEdit->setVisible( false );
        ui.thirdLabel->setVisible( false );
        ui.thirdLineEdit->setVisible( false );
        break;
    case 2:
        ui.thirdLabel->setVisible( false );
        ui.thirdLineEdit->setVisible( false );
        ui.firstLineEdit->setText( QString( "%1" ).arg( playersScoreVector[ 0 ] ) );
        ui.secondLineEdit->setText( QString( "%1" ).arg( playersScoreVector[ 1 ] ) );
        break;

    case 3:
        ui.firstLineEdit->setText( QString( "%1" ).arg( playersScoreVector[ 0 ] ) );
        ui.secondLineEdit->setText( QString( "%1" ).arg( playersScoreVector[ 1 ] ) );
        ui.thirdLineEdit->setText( QString( "%1" ).arg( playersScoreVector[ 2 ] ) );
        break;

    default:
        break;
    }
}

CorrectionDialog::~CorrectionDialog()
{

}

void CorrectionDialog::onOk()
{
    switch (m_playersScoreVector.count())
    {
    case 2:
        m_playersScoreVector[ 0 ] = ui.firstLineEdit->text().toInt();
        m_playersScoreVector[ 1 ] = ui.secondLineEdit->text().toInt();
        break;

    case 3:
        m_playersScoreVector[ 0 ] = ui.firstLineEdit->text().toInt();
        m_playersScoreVector[ 1 ] = ui.secondLineEdit->text().toInt();
        m_playersScoreVector[ 2 ] = ui.thirdLineEdit->text().toInt();
        break;

    default:
        break;
    }

    accept();
}

const QVector<int> & CorrectionDialog::playersScoreVector() const
{
    return m_playersScoreVector;
}
